<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>swiper叠加轮播图</title>
</head>

<body>
    <link rel="stylesheet" href="https://unpkg.com/swiper@7/swiper-bundle.min.css" />
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        /* 外层容器 */
        .swiper {
            width: 1310px;
            height: 482px;
        }

        .swiper-wrapper {
            width: 1216px;
            height: 482px;
        }

        /* 轮播项 */
        .swiper .swiper-slide {
            width: 800px;
            height: 482px;
            font-size: 32px;
            font-weight: 500;
            color: #ffffff;
            /* 文字垂直居中 */
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .swiper .swiper-slide img {
            width: 100%;
            height: 100%;
        }

        /* 色彩来源：https://color.uisdc.com/ */
        .swiper .swiper-slide-1 {
            background-color: #425066;
        }

        .swiper .swiper-slide-2 {
            background-color: #b88ed6;
        }

        .swiper .swiper-slide-3 {
            background-color: #9d2933;
        }

        .swiper .swiper-slide-4 {
            background-color: #003371;
        }

        .swiper .swiper-slide-5 {
            background-color: #4c8dae;
        }

        .swiper .swiper-slide-6 {
            background-color: #72db09;
        }

        .swiper .swiper-slide-7 {
            background-color: #f72905;
        }

        .swiper .swiper-slide-8 {
            background-color: #03a8fb;
        }

        .swiper .swiper-slide-9 {
            background-color: #9803fb;
        }

        /* .swiper-button-prev {
            width: 34px;
            height: 34px;
            background: url("./img/prev.png") no-repeat;
            background-size: 100% 100%;
        }
        .swiper-button-next {
            width: 34px;
            height: 34px;
            background: url("./img/next.png") no-repeat;
            background-size: 100% 100%;
        }
         去除默认的操作按钮样式
        .swiper-button-next:after,
        .swiper-button-prev:after {
            display: none;
        } */
    </style>
    <div class="swiper">
        <div class="swiper-wrapper">
            <div class="swiper-slide swiper-slide-1">
                <img src="./banner/1.png">
            </div>
            <div class="swiper-slide swiper-slide-2">
                <img src="./banner/2.png">
            </div>
            <div class="swiper-slide swiper-slide-3">
                <img src="./banner/3.png">
            </div>
            <div class="swiper-slide swiper-slide-4">
                <img src="./banner/4.png">
            </div>
            <div class="swiper-slide swiper-slide-5">
                <img src="./banner/5.png">
            </div>
            <div class="swiper-slide swiper-slide-6">
                <img src="./banner/6.png">
            </div>
        </div>
        <div class="swiper-button-prev"></div>
        <div class="swiper-button-next"></div>
    </div>
    <script src="https://unpkg.com/swiper@7/swiper-bundle.min.js"></script>
    <script>
        const swiper = new Swiper('.swiper', {
            initialSlide: Math.floor(5 / 2), //默认第几个在中心位置显示，总数量中间的一个，计算
            autoplay: true,
            // 容器能够显示的slide数量，可以用来调节中间slide占比大小（为了达到设计图的尺寸），
            // slide不能固定宽度，会影响滑动效果，所以这里用比例调节
            slidesPerView: "auto", // 每个slide的宽度：外层容器 1310 / slidesPerView = 387
            // 当前active的slide居中-最前面的大图
            centeredSlides: true,
            autoplay: {
                delay: 3000, // 自动轮播的时间间隔（单位：毫秒）
                disableOnInteraction: false, // 用户交互后是否停止自动轮播（false表示不停止）
            },
            effect: "creative",
            loop: true,
            grabCursor: true,
            creativeEffect: {
                prev: {
                    translate: [-115, 0, 0], // 偏移量
                    scale: 0.85, // 缩放量
                    shadow: true, // 是否加阴影
                },
                next: {
                    translate: [140, 0, 0],
                    scale: 0.85,
                    shadow: true,
                },
                limitProgress: Math.floor(5 / 2), // 显示五个堆叠的最重要的这个属性，后面依次以前面属性等比配置
                shadowPerProgress: true, //是否等比配置透明度
            },
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
        });
        // 监听改变事件
        swiper.on('slideChange', (e) => {
            console.log(e.realIndex);
        });
    </script>
</body>

</html>